package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.canteen.domain.SetmealDish;
import com.ruoyi.canteen.service.ISetmealDishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐与菜品关联Controller
 *
 * @author ruoyi
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/canteen/setmeal_dish")
public class SetmealDishController extends BaseController
{
    @Autowired
    private ISetmealDishService setmealDishService;

    /**
     * 查询套餐与菜品关联列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:list')")
    @GetMapping("/list")
    public TableDataInfo list(SetmealDish setmealDish)
    {
        startPage();
        List<SetmealDish> list = setmealDishService.selectSetmealDishList(setmealDish);
        return getDataTable(list);
    }

    /**
     * 导出套餐与菜品关联列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:export')")
    @Log(title = "套餐与菜品关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SetmealDish setmealDish)
    {
        List<SetmealDish> list = setmealDishService.selectSetmealDishList(setmealDish);
        ExcelUtil<SetmealDish> util = new ExcelUtil<SetmealDish>(SetmealDish.class);
        util.exportExcel(response, list, "套餐与菜品关联数据");
    }

    /**
     * 获取套餐与菜品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(setmealDishService.selectSetmealDishById(id));
    }

    /**
     * 新增套餐与菜品关联
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:add')")
    @Log(title = "套餐与菜品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SetmealDish setmealDish)
    {
        return toAjax(setmealDishService.insertSetmealDish(setmealDish));
    }

    /**
     * 修改套餐与菜品关联
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:edit')")
    @Log(title = "套餐与菜品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SetmealDish setmealDish)
    {
        return toAjax(setmealDishService.updateSetmealDish(setmealDish));
    }

    /**
     * 删除套餐与菜品关联
     */
    @PreAuthorize("@ss.hasPermi('canteen:setmeal_dish:remove')")
    @Log(title = "套餐与菜品关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(setmealDishService.deleteSetmealDishByIds(ids));
    }
}
